package com.education.expenses.web.controller;

import com.education.expenses.common.dto.GridDTO;
import com.education.expenses.common.dto.ResponseDTO;
import com.education.expenses.common.dto.UserProfileDTO;
import com.education.expenses.entity.Role;
import com.education.expenses.facade.AdminFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * User: Alex Kasianik
 * Date: 17.08.12
 * Time: 6:30
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminController {

    @Autowired
    AdminFacade adminFacade;

    @RequestMapping(value = "/userslist")
    public @ResponseBody GridDTO<UserProfileDTO> reports(
            @RequestParam("rows") Integer rows, @RequestParam("page") Integer page) {

//        GridDTO<UserProfileDTO> gridDTO = new GridDTO<UserProfileDTO>();
//        gridDTO.setPageNumber(page.longValue());
//        gridDTO.setPageCount(1L);
//        gridDTO.setRecordsCount(2L);

        GridDTO<UserProfileDTO> gridDTO = adminFacade.getUserProfiles(page, rows);
        return gridDTO;
    }

    @RequestMapping(value = "/changerole", method = RequestMethod.POST)
    public @ResponseBody ResponseDTO approveRoleMark(@RequestParam("id") Integer id) {

        adminFacade.changeRole(id, Role.APPROVER_ROLE);

        ResponseDTO response = new ResponseDTO();

        response.setSuccess(true);
        response.setMessage("Action successful");
        return response;
    }

}

